package com.steshov.trainer.utils;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ToggleButton;

import com.steshov.trainer.R;
import com.steshov.trainer.activities.ExerciseActivity;
import com.steshov.trainer.activities.Index;
import com.steshov.trainer.activities.TaskActivity;

public class Adapters {

	public static OnClickListener toTasksPage() {

		OnClickListener listener = new OnClickListener() {
			@Override
			public void onClick(View v) {
				Activity context = (Activity) v.getContext();
				Animation pressing = AnimationUtils.loadAnimation(context,
						R.anim.buttonpress);
				v.startAnimation(pressing);
				Intent myIntent = new Intent(v.getContext(), TaskActivity.class);
				context.startActivityForResult(myIntent, 0);
				context.finish();
			}
		};
		return listener;
	}

	public static OnClickListener toMainPage() {
		OnClickListener listener = new OnClickListener() {
			@Override
			public void onClick(View v) {
				Activity context = (Activity) v.getContext();
				Animation pressing = AnimationUtils.loadAnimation(context,
						R.anim.buttonpress);
				v.startAnimation(pressing);
				Intent myIntent = new Intent(v.getContext(), Index.class);
				context.startActivityForResult(myIntent, 0);
				context.finish();
			}
		};
		return listener;
	}

	public static OnClickListener toExercisePage() {
		OnClickListener listener = new OnClickListener() {
			@Override
			public void onClick(View v) {
				Activity context = (Activity) v.getContext();
				Animation pressing = AnimationUtils.loadAnimation(context,
						R.anim.buttonpress);
				v.startAnimation(pressing);
				Intent myIntent = new Intent(v.getContext(),
						ExerciseActivity.class);
				myIntent.putExtra("stress", ((Index)context).getStressLevel());
				context.startActivityForResult(myIntent, 0);
				context.finish();
			}
		};
		return listener;
	}

	public static OnClickListener toglingGeneration() {
		OnClickListener onClickListener = new OnClickListener() {
			@Override
			public void onClick(View v) {
				Index context = (Index) v.getContext();
				ExerciseGenerator generator = new ExerciseGenerator(context);
				ToggleButton but = (ToggleButton) v;
				App.generateButtonFlag = (but.isChecked() ? true : false);
				Reservation.put(context, "generateButtonFlag",
						App.generateButtonFlag.toString());
				generator.execute();				
			}
		};
		return onClickListener;
	}
}
